package com.ply.flashsalessystem.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author XiaoPan
 * date: 2022/1/15 13:43
 * <p>
 * action:  制定一些规则  判断 字符串
 */
public class RuleUtils {
    //name 规则  :只允许 字母开头  注册 最少 6个 最大 12个
    public static String iphoneError = "电话格式不对";
    public static String nameError = "name格式不对,name要以字符开头,并且最短6位,最长12位";
    public static String pwdError = "密码最短为6位,最长位18位";

    private final static  Pattern namePattern = Pattern.compile("^[a-zA-Z].{5,11}$");

//    private final static  Pattern iphonePattern = Pattern.compile("[1-9]+[0-9]{10}");
//    private final static  Pattern iphonePattern = Pattern.compile("^((13[0-9])|(15[^4,\\\\D])|(18[0,5-9]))\\\\d{8}$");
    private final static  Pattern iphonePattern = Pattern.compile("^[1-9]\\d{10}$");

    private final static  Pattern pwdPattern = Pattern.compile("^.{6,18}$");

    /**
     * 用户名 判断规则
     * @param name 用户name
     */
    public static boolean userName(String name){
        return checkPattern(namePattern,name);
    }

    /**
     *  电话判断
     * @param iphone 电话
     */
    public static boolean iphonePattern(String iphone){
        return checkPattern(iphonePattern,iphone);
    }

    /**
     * 密码判断
     * @param pwd 密码
     */
    public static boolean pwdPattern(String pwd){
        return checkPattern(pwdPattern,pwd);
    }
    private static boolean checkPattern(Pattern p,String value){
        Matcher matcher = p.matcher(value);
        return matcher.matches();
    }
}
